Skip to content

Emit gen_ai.* attributes on APM spans - #12450

Open
mz1119 wants to merge 10 commits into
masterfrom
max.zhang/llmobs-gen-ai-apm-tags
Open

mz1119 wants to merge 10 commits into
masterfrom
max.zhang/llmobs-gen-ai-apm-tags

Conversation

@mz1119

@mz1119 mz1119 commented Sep 10, 2026

Copy link
Copy Markdown

What Does This Do

Emits the scalar gen_ai.* attributes onto APM spans, making them indexed APM tags:

  • meta: gen_ai.operation.name, gen_ai.request.model, gen_ai.provider.name, gen_ai.application.name, gen_ai.conversation.id
  • metrics: gen_ai.usage.{input,output,total,cache_read_input,cache_write_input,reasoning_output}_tokens

GenAiApmTags reads the values back off the span's _ml_obs_tag.* / _ml_obs_metric.* keys at finish time and is called from both emission sites: manual SDK spans (DDLLMObsSpan.finish) and auto-instrumentation (OpenAiDecorator.doBeforeFinish). Since LLMObsSpanMapper only serializes _ml_obs_* keys, the unprefixed tags land on the APM span only.

Alongside them it sets the internal _dd.llmobs.artificial_gen_ai_tags tag, marking the attributes as tracer-written rather than user-annotated. Without it the backend processor treats the APM span as a user-annotated gen_ai span and creates a duplicate LLM Observability span.

Message bodies (input, output, tool definitions, retrieval documents) stay off the APM span and keep coming from the LLMObs track. Port of DataDog/dd-trace-py#20083, DataDog/dd-trace-py#20411 and DataDog/dd-trace-js#10261.

Motivation

The APM trace UI merges these keys from the LLMObs track client-side, so the values render but aren't indexed. You can't filter, facet, or monitor on model, provider, or token usage in APM.

Testing

disabled span:
https://app.datadoghq.com/u/d4735e3a/haW-kUa-8V4

enabled span:
https://app.datadoghq.com/u/d4735e3a/rWc-4gR-dGd

🤖 Generated with Claude Code

Write the scalar gen_ai.* subset of an LLM Observability span onto the
APM span, so model, provider, application, conversation and token usage
become indexed, searchable APM tags.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@mz1119 mz1119 added type: feature Enhancements and improvements comp: mlobs ML Observability (LLMObs) tag: ai generated Largely based on code generated by an AI or LLM labels Sep 10, 2026
@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Sep 10, 2026

Copy link
Copy Markdown

🎯 Code Coverage (details)
Patch Coverage: 94.87%
Overall Coverage: 57.48% (-1.56%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 3a4ee32 | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.64 s 14.60 s [-0.5%; +1.0%] (no difference)
startup:insecure-bank:tracing:Agent 13.54 s 13.64 s [-1.7%; +0.3%] (no difference)
startup:petclinic:appsec:Agent 16.88 s 16.71 s [+0.1%; +2.0%] (maybe worse)
startup:petclinic:iast:Agent 16.26 s 16.48 s [-7.5%; +4.8%] (unstable)
startup:petclinic:profiling:Agent 16.62 s 16.75 s [-1.5%; +0.0%] (no difference)
startup:petclinic:sca:Agent 16.88 s 16.61 s [+0.6%; +2.7%] (maybe worse)
startup:petclinic:tracing:Agent 16.00 s 16.11 s [-1.7%; +0.3%] (no difference)

Commit: 3a4ee322 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@mz1119

mz1119 commented Sep 10, 2026

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-11T17:28:18.683154Z 1527dca Draft marked ready
🔒 Security Review Completed 2026-09-11T17:29:41.733301Z 1527dca Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: f1d46cfe83

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: f1d46cfe83

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

mz1119 and others added 2 commits September 11, 2026 10:26
The openai-java instrumentation keeps tracing when LLM Observability is
disabled, and the operation, model, provider and ml_app are all known on
that path. Token usage and conversation id are not computed there, so
they stay unreported.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The repository does not accept new .groovy files. The module already has
a JUnit forked-test base for LLMObs configurations, so the coverage moves
there.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@mz1119
mz1119 marked this pull request as ready for review September 11, 2026 17:23
@mz1119
mz1119 requested review from a team as code owners September 11, 2026 17:23
@mz1119
mz1119 requested review from vandonr and removed request for a team September 11, 2026 17:23

@datadog-datadog-us1-prod datadog-datadog-us1-prod Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datadog Autotest: PASS

More details

The finish-time mapping reads only scalar LLM Observability tags. It keeps message bodies off APM spans and limits usage metrics to LLM and embedding spans.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Datadog Autotest · Commit 1527dca · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ncybul

ncybul commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: faac2ec6f8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal-api/src/main/java/datadog/trace/api/llmobs/GenAiApmTags.java Outdated
mz1119 and others added 3 commits September 11, 2026 16:32
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Both tests in the class produce an openai.request span, so taking the first
one written let a late trace from the sibling test be asserted on.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
mz1119 and others added 3 commits September 16, 2026 16:33
The attributes are derived from the LLMObs tag set, which the openai
decorators do not build with LLM Observability off. Drop the fallback that
resolved operation, model and ml_app from APM tags instead, and collapse
GenAiApmTags back to a single apply(span).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sets _dd.llmobs.artificial_gen_ai_tags alongside the gen_ai.* attributes so
the backend processor does not treat them as a user annotation and create a
duplicate LLM Observability span.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: mlobs ML Observability (LLMObs) tag: ai generated Largely based on code generated by an AI or LLM type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants